From: kfraser@localhost.localdomain Date: Fri, 31 Aug 2007 14:44:38 +0000 (+0100) Subject: Make XEN_DOMCTL_destroydomain hypercall preemptible, in a way that is X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~14987^2~21 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=e815cb4b18f3261a4e97297aabbf73d9b3a27244;p=xen.git Make XEN_DOMCTL_destroydomain hypercall preemptible, in a way that is visible to the caller (via -EAGAIN return code). This prevents softlockup in dom0 kernel, due to the hypercall taking too long to execute on very large (multi-multi-gigabyte) domains. Signed-off-by: Isaku Yamahata Signed-off-by: Keir Fraser --- diff --git a/xen/arch/ia64/xen/domain.c b/xen/arch/ia64/xen/domain.c index 1cda521a4e..7914a81406 100644 --- a/xen/arch/ia64/xen/domain.c +++ b/xen/arch/ia64/xen/domain.c @@ -936,7 +936,7 @@ static void relinquish_memory(struct domain *d, struct list_head *list) spin_unlock_recursive(&d->page_alloc_lock); } -void domain_relinquish_resources(struct domain *d) +int domain_relinquish_resources(struct domain *d) { /* Relinquish guest resources for VT-i domain. */ if (d->vcpu[0] && VMX_DOMAIN(d->vcpu[0])) @@ -954,6 +954,8 @@ void domain_relinquish_resources(struct domain *d) /* Free page used by xen oprofile buffer */ free_xenoprof_pages(d); + + return 0; } unsigned long diff --git a/xen/arch/powerpc/domain.c b/xen/arch/powerpc/domain.c index 312fffdab2..c0f78bf797 100644 --- a/xen/arch/powerpc/domain.c +++ b/xen/arch/powerpc/domain.c @@ -313,13 +313,13 @@ static void relinquish_memory(struct domain *d, struct list_head *list) spin_unlock_recursive(&d->page_alloc_lock); } -void domain_relinquish_resources(struct domain *d) +int domain_relinquish_resources(struct domain *d) { relinquish_memory(d, &d->xenpage_list); relinquish_memory(d, &d->page_list); xfree(d->arch.foreign_mfns); xfree(d->arch.p2m); - return; + return 0; } void arch_dump_domain_info(struct domain *d) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 0f4077f48c..203ca8ba2a 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1717,7 +1717,7 @@ static void vcpu_destroy_pagetables(struct vcpu *v) v->arch.cr3 = 0; } -void domain_relinquish_resources(struct domain *d) +int domain_relinquish_resources(struct domain *d) { struct vcpu *v; @@ -1754,6 +1754,8 @@ void domain_relinquish_resources(struct domain *d) if ( is_hvm_domain(d) ) hvm_domain_relinquish_resources(d); + + return 0; } void arch_dump_domain_info(struct domain *d) diff --git a/xen/common/domain.c b/xen/common/domain.c index 0e48eeeda4..a470cc8e73 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -245,7 +245,7 @@ struct domain *domain_create( return d; fail: - d->is_dying = 1; + d->is_dying = DOMDYING_dead; atomic_set(&d->refcnt, DOMAIN_DESTROYED); if ( init_status & INIT_arch ) arch_domain_destroy(d); @@ -303,26 +303,37 @@ struct domain *rcu_lock_domain_by_id(domid_t dom) } -void domain_kill(struct domain *d) +int domain_kill(struct domain *d) { - domain_pause(d); + int rc = 0; + + if ( d == current->domain ) + return -EINVAL; - /* Already dying? Then bail. */ - if ( test_and_set_bool(d->is_dying) ) + /* Protected by domctl_lock. */ + switch ( d->is_dying ) { - domain_unpause(d); - return; + case DOMDYING_alive: + domain_pause(d); + d->is_dying = DOMDYING_dying; + evtchn_destroy(d); + gnttab_release_mappings(d); + case DOMDYING_dying: + rc = domain_relinquish_resources(d); + page_scrub_kick(); + if ( rc != 0 ) + { + BUG_ON(rc != -EAGAIN); + break; + } + d->is_dying = DOMDYING_dead; + put_domain(d); + send_guest_global_virq(dom0, VIRQ_DOM_EXC); + case DOMDYING_dead: + break; } - evtchn_destroy(d); - gnttab_release_mappings(d); - domain_relinquish_resources(d); - put_domain(d); - - /* Kick page scrubbing after domain_relinquish_resources(). */ - page_scrub_kick(); - - send_guest_global_virq(dom0, VIRQ_DOM_EXC); + return rc; } diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 0b13cd9f69..6ef83e8fd2 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -114,10 +114,10 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info) info->cpu_time = cpu_time; info->flags = flags | - (d->is_dying ? XEN_DOMINF_dying : 0) | - (d->is_shut_down ? XEN_DOMINF_shutdown : 0) | - (d->is_paused_by_controller ? XEN_DOMINF_paused : 0) | - (d->debugger_attached ? XEN_DOMINF_debugged : 0) | + ((d->is_dying == DOMDYING_dead) ? XEN_DOMINF_dying : 0) | + (d->is_shut_down ? XEN_DOMINF_shutdown : 0) | + (d->is_paused_by_controller ? XEN_DOMINF_paused : 0) | + (d->debugger_attached ? XEN_DOMINF_debugged : 0) | d->shutdown_code << XEN_DOMINF_shutdownshift; if ( is_hvm_domain(d) ) @@ -422,18 +422,7 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domctl_t) u_domctl) ret = -ESRCH; if ( d != NULL ) { - ret = xsm_destroydomain(d); - if ( ret ) - goto destroydomain_out; - - ret = -EINVAL; - if ( d != current->domain ) - { - domain_kill(d); - ret = 0; - } - - destroydomain_out: + ret = xsm_destroydomain(d) ? : domain_kill(d); rcu_unlock_domain(d); } } diff --git a/xen/include/asm-ia64/domain.h b/xen/include/asm-ia64/domain.h index 6a8af521f9..40bc6e52ad 100644 --- a/xen/include/asm-ia64/domain.h +++ b/xen/include/asm-ia64/domain.h @@ -18,7 +18,6 @@ struct p2m_entry; struct tlb_track; #endif -extern void domain_relinquish_resources(struct domain *); struct vcpu; extern void relinquish_vcpu_resources(struct vcpu *v); extern void vcpu_share_privregs_with_guest(struct vcpu *v); diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index dd19c966b7..aa8c72f0ac 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -45,7 +45,7 @@ void arch_domain_destroy(struct domain *d); int arch_set_info_guest(struct vcpu *, vcpu_guest_context_u); void arch_get_info_guest(struct vcpu *, vcpu_guest_context_u); -void domain_relinquish_resources(struct domain *d); +int domain_relinquish_resources(struct domain *d); void dump_pageframe_info(struct domain *d); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 9135ca3b44..f863f4a837 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -194,7 +194,7 @@ struct domain /* Are any VCPUs polling event channels (SCHEDOP_poll)? */ bool_t is_polling; /* Is this guest dying (i.e., a zombie)? */ - bool_t is_dying; + enum { DOMDYING_alive, DOMDYING_dying, DOMDYING_dead } is_dying; /* Domain is paused by controller software? */ bool_t is_paused_by_controller; @@ -338,7 +338,7 @@ static inline struct domain *rcu_lock_current_domain(void) struct domain *get_domain_by_id(domid_t dom); void domain_destroy(struct domain *d); -void domain_kill(struct domain *d); +int domain_kill(struct domain *d); void domain_shutdown(struct domain *d, u8 reason); void domain_resume(struct domain *d); void domain_pause_for_debugger(void);